/*
 * @Description: exec（）、test（）、toString()
 * @Author: zzj
 * @Date: 2021-09-14 17:08:02
 * @LastEditors: zzj
 * @LastEditTime: 2021-09-14 17:14:28
 */
var str="ef ab 12 3acb abcd 33";
var pattern=new RegExp("ab","igm");
//==> var pattern=/ab/igm

var result = pattern.exec(str);
console.log(result);//[ 'ab', index: 3, input: 'ef ab 12 3acb abcd 33', groups: undefined ]
console.log(pattern.lastIndex);//5
console.log(result[0]);//ab
console.log(result.index);//3
console.log(result.input === str);  //true

var result = pattern.exec(str);
console.log(result);//[ 'ab', index: 14, input: 'ef ab 12 3acb abcd 33', groups: undefined ]
console.log(pattern.lastIndex);//16

var result = pattern.exec(str);
console.log(result);//null
console.log(pattern.lastIndex);//0

var result = pattern.exec(str);
console.log(result);//[ 'ab', index: 3, input: 'ef ab 12 3acb abcd 33', groups: undefined ]
console.log(pattern.lastIndex);//5

var result = pattern.test(str);
console.log(result,pattern.lastIndex);//true 16
var result = pattern.test(str);
console.log(result,pattern.lastIndex);//false 0
var result = pattern.test(str);
console.log(result,pattern.lastIndex);//true 5

//pattern.global=false;//这种设置无效
console.log(pattern.global);  //true
var pattern2=/ab/im;
var result = pattern2.test(str);
console.log(result,pattern2.lastIndex);//true 0
var result = pattern2.test(str);
console.log(result,pattern2.lastIndex);//true 0
var result = pattern2.test(str);
console.log(result,pattern2.lastIndex);//true 0